<?php 
namespace Admin\Controller;


/**
 * 商品品牌分类控制器
 */

class BrandsController extends BaseController {
	/**
	 * 分页列表
	 */
	public function index() {
		$m = D('Admin/GoodsCats');
		$cats = $m->queryByList(0);
		
		$this->assign('cats',$cats);
		self::WDAssigns();
		$m = D('Admin/Brands');
    	$page = $m->queryByPage();
    	
    	foreach ($page['root'] as &$value) {
    		$value['branddesc'] = html_entity_decode(stripslashes($value['branddesc']));
    	}
    	$pager = new \Think\Page($page['total'],$page['pageSize']);// 实例化分页类 传入总记录数和每页显示的记录数
    	$page['pager'] = $pager->show();
    	$this->assign('Page',$page);
        $this->view->display("/brands/list");	
	}

	/**
	 * 跳到新增、修改页面
	 */
	public function toEdit() {
		// 获取商品分类
		$m = D('Admin/GoodsCats');
		$cats = $m->queryByList(0);
		$this->assign('cats',$cats);

		$m = D('Admin/Brands');
		$object = array();
		if (I('id',0)>0) {
			$object = $m->get();
		}else{
			$object	= $m->getModel();
		}
		$this->assign('object',$object);
		$this->display("/brands/edit");


	}

	/**
	 * 新增/修改操作
	 */
	public function edit(){
		$m = D('Admin/Brands');
    	$rs = array();
    	if(I('id',0)>0){

    		$rs = $m->edit();
    	}else{
    		
    		$rs = $m->insert();
    	}
    	$this->ajaxReturn($rs);
	}

	/**
	 * 列表查询
	 */
    public function queryByList(){
    	$this->isAjaxLogin();
		$m = D('Admin/Brands');
		$list = $m->queryList();
		$rs = array();
		$rs['status'] = 1;
		$rs['list'] = $list;
		$this->ajaxReturn($rs);
	}






}


?>